package com.example.echoewish.util;

import com.example.echoewish.econstant.Constant;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

//该工具类作用是不需要重复写retrofit配置 利于更改。
public class ServiceCreator {

    private static  final String base_url= Constant.ROOT_URL;
    private static final OkHttpClient client = new OkHttpClient.Builder().
            connectTimeout(1, TimeUnit.SECONDS).
            readTimeout(1, TimeUnit.SECONDS).
            writeTimeout(1, TimeUnit.SECONDS).build();


    private Retrofit retrofit=new Retrofit.Builder().
            baseUrl(base_url).
            addConverterFactory(GsonConverterFactory.create()).
            client(client).
            build();

    //泛型
    public <T> T create(Class<T> serviceClass)
    {
        return retrofit.create(serviceClass);
    }
}
